/* Wage Changes by Type of Transitions */
/* and by job characteristics */
/* By destination: relational vs non-relational */

#delimit ;

*version 8;
set mem 100m;
 
log using table7, replace text;
 


/* Transition to Market */

u psid76_2004_jleo;



/* wage changes between types of jobs */


gen logw_change=lw-lw[_n-1] if jobmatch~=jobmatch[_n-1] & id==id[_n-1];
gen lag_tenure=tenure[_n-1] if jobmatch~=jobmatch[_n-1] & id==id[_n-1];


drop if jobmatch[_n-1]==. | relational_job[_n-1]==. | id[_n-1]==.;


gen  type_change=1 if (jobmatch~=jobmatch[_n-1]) & 
(relational_job[_n-1]==1) 
& (id==id[_n-1]);

replace type_change=2 if (jobmatch~=jobmatch[_n-1]) & 
(relational_job[_n-1]==0) 
& (id==id[_n-1]);


keep if id==id[_n-1] & jobmatch~=jobmatch[_n-1];



gen R_to_Any=type_change==1;
gen NR_to_Any=type_change==2;

gen tenure_R=lag_tenure*R_to_Any;
gen tenure_NR=lag_tenure*NR_to_Any;

drop quit layoff;
 
gen quit=reashe==4 | reashu==4 | reashu2==4 | reashu==8 | reashu2==8;
gen layoff=(reashe==1 | reashe==3 | reashe==8) | 
  (reashu==1 | reashu==3) | (reashu2==1 | reashu2==3);

drop if (layoff==1 & quit==1) | (quit==0 & layoff==0);

xtset id year;


drop if collbarg==. | nonwhite==. | married==. | occcat==. 
| ind1dg==. | educ==. | potexp==. | tenure==.;






/* R_to_Any and NR_to_Any      */
/* Full sample of job changers */

xi: reg logw_change R_to_Any NR_to_Any
  [aw=iweight],
cluster(id) nocons;

test R_to_Any=NR_to_Any;
pause;


xi: reg logw_change R_to_Any NR_to_Any
 i.year lag_tenure tenure_R tenure_NR
    [aw=iweight],
cluster(id) nocons;
test R_to_Any=NR_to_Any;
pause;


/*quits */

xi: reg logw_change R_to_Any NR_to_Any
  [aw=iweight] if quit==1,
cluster(id) nocons;
test R_to_Any=NR_to_Any;
pause;


xi: reg logw_change R_to_Any NR_to_Any
 i.year lag_tenure tenure_R tenure_NR
    [aw=iweight] if quit==1,
cluster(id) nocons;
test R_to_Any=NR_to_Any;
pause;

/*layoffs */

xi: reg logw_change R_to_Any NR_to_Any
  [aw=iweight] if layoff==1,
cluster(id) nocons;
test R_to_Any=NR_to_Any;
pause;

xi: reg logw_change R_to_Any NR_to_Any
 i.year lag_tenure tenure_R tenure_NR
    [aw=iweight] if layoff==1,
cluster(id) nocons;
test R_to_Any=NR_to_Any;
pause;




clear;



/* Transition from Market */


u psid76_2004_jleo;

/* wage changes between types of jobs */


gen logw_change=lw-lw[_n-1] if jobmatch~=jobmatch[_n-1] & id==id[_n-1];
gen lag_tenure=tenure[_n-1] if jobmatch~=jobmatch[_n-1] & id==id[_n-1];

drop if jobmatch[_n-1]==. | relational_job[_n-1]==. | id[_n-1]==.;

gen  type_change=1 if (jobmatch~=jobmatch[_n-1]) & 
(relational_job==1) 
& (id==id[_n-1]);

replace type_change=2 if (jobmatch~=jobmatch[_n-1]) & 
(relational_job==0) 
& (id==id[_n-1]);



keep if id==id[_n-1] & jobmatch~=jobmatch[_n-1];


gen Any_to_R=type_change==1;
gen Any_to_NR=type_change==2;


drop quit layoff;

gen quit=reashe==4 | reashu==4 | reashu2==4 | reashu==8 | reashu2==8;
gen layoff=(reashe==1 | reashe==3 | reashe==8) | 
  (reashu==1 | reashu==3) | (reashu2==1 | reashu2==3);

drop if (layoff==1 & quit==1) | (quit==0 & layoff==0);


drop if collbarg==. | nonwhite==. | married==. | occcat==. 
| ind1dg==. | educ==. | potexp==. | tenure==.;



gen tenure_R=lag_tenure*Any_to_R;
gen tenure_NR=lag_tenure*Any_to_NR;


/* Full sample of job changers */

xi: reg logw_change Any_to_R Any_to_NR
  [aw=iweight], nocons
cluster(id);
test Any_to_R=Any_to_NR;
pause;
xi: reg logw_change Any_to_R Any_to_NR
i.year lag_tenure tenure_R tenure_NR  [aw=iweight], nocons
cluster(id);
test Any_to_R=Any_to_NR;
pause;



/*quits */


xi: reg logw_change Any_to_R Any_to_NR
  [aw=iweight] if quit==1, nocons
cluster(id);
test Any_to_R=Any_to_NR;
pause;

xi: reg logw_change Any_to_R Any_to_NR
i.year lag_tenure tenure_R tenure_NR  [aw=iweight] if quit==1, nocons
cluster(id);
test Any_to_R=Any_to_NR;
pause;


/*layoffs */


xi: reg logw_change Any_to_R Any_to_NR
  [aw=iweight] if layoff==1, nocons
cluster(id);
test Any_to_R=Any_to_NR;
pause;
xi: reg logw_change Any_to_R Any_to_NR
i.year lag_tenure tenure_R tenure_NR  [aw=iweight] if layoff==1, nocons
cluster(id);
test Any_to_R=Any_to_NR;
pause;



clear;
log close;


